﻿#ifndef USERRELATIONSERVICE_H
#define USERRELATIONSERVICE_H

#include <QObject>
#include "userrelationnetworkaccessmanager.h"
#include "usermanagetableview.h"
#include "usermanagetreeview.h"
#include "user.h"
#include "company.h"
#include "excelimportthread.h"
#include <QPushButton>

class UserRelationService : public QObject
{
    Q_OBJECT
public:
    explicit UserRelationService(QObject *parent = nullptr);

    void queryPlatformUser(QWidget *widget, QString username, QString companyId);

    void addPlatformUser(
            QWidget *widget,
            QPushButton *button,
            QString targetUsername,
            UserRelation::RelationType type);

    void updateUserRelationData(QWidget *widget, UserRelation::RelationType type);

    void queryUserRelation(
            UserManageTableView *tableView,
            UserManageTreeView *treeView,
            bool isShowPlatformUser,
            QString overallQuery,
            QString nickNameQuery,
            QString contactQuery,
            QString telQuery);

    void addNonPlatformUser(
            QWidget *widget,
            QPushButton *button,
            UserRelation::RelationType type,
            QString nickName,
            QString contact,
            QString tel,
            QString remark,
            QString primaryDirectory,
            QString secondaryDirectory);

    void queryUserRelationDetail(QWidget *widget, QString username, QString companyId);

    void buildSubAccount(QWidget *widget, QString targetUsername, UserRelation::RelationType type);

    void changeUserRelation(QWidget *widget, QString targetUsername, UserRelation::RelationType type);

    void updateUserRelation(
            QWidget *widget,
            QString targetUsername,
            UserRelation::RelationType type,
            QString urClientName,
            QString urContact,
            QString urTel,
            QString urRemark,
            QString urCredit,
            QString urPrimaryDirectory,
            QString urSecondaryDirectory,
            QString userNickName,
            QString userPosition,
            QString userTel,
            QString userMobile,
            QString userQQ,
            QString userWechat,
            QString companyCompanyName,
            QString companyContact,
            QString companyTel,
            QString companyFax,
            QString companyWebsite,
            QString companyEmail,
            QString companyProvince,
            QString companyCity,
            QString companyDistrict,
            QString companyAddress,
            QString companyAccount,
            QString companyIntroduction,
            QString companyTicketCompanyName,
            QString companyTaxNum,
            QString companyBank,
            QString companyTicketAccount,
            QString companyTicketTel,
            QString companyTicketAddress);

    void uploadUserRelation(QWidget *widget, UserRelation::RelationType type, QList<UserRelation*> relations);

    bool checkDataHeader(UserRelation::RelationType type, QList<QVariant> header);

    UserRelation* checkData(UserRelation::RelationType type, int index, QList<QVariant> dataItem);

    QList<UserRelation*> checkData(UserRelation::RelationType type, QList<QList<QVariant>> data);

    void adjustUserRelationFinance(
            QWidget *widget,
            QPushButton *button,
            UserRelation *relation,
            QString relatedMessageId,
            double ticketValue,
            double moneyValue);

    void deleteUserRelation(
            QWidget *widget,
            UserRelation *relation);

signals:
    void queryPlatformUserSuccess(User &user, Company &company);

    void addPlatformUserFailed();

    void queryUserRelationDetailSuccess(User &user, Company &company);

    void buildSubAccountSuccess();

    void changeUserRelationSuccess();

    void adjustUserRelationFinanceSuccess();

    void uploadUserRelationSuccess();

    void updateUserRelationDataSuccess(QList<UserRelation*> relations);
public slots:

private:
    UserRelationNetworkAccessManager *manager;
    ExcelImportThread *importThread;
};

#endif // USERRELATIONSERVICE_H
